package com.woniuxy.project.controller;

import com.woniuxy.commons.entity.Invest;
import com.woniuxy.commons.request.ResPage;
import com.woniuxy.commons.request.ResponseResult;
import com.woniuxy.project.entity.IndexData;
import com.woniuxy.project.service.ProjectService;
import com.woniuxy.project.vo.AddProjectVo;
import com.woniuxy.commons.vo.ProjectVo;
import com.woniuxy.project.vo.ReviewProjectVo;
import com.woniuxy.commons.vo.SearchProjectVo;
import com.woniuxy.project.vo.SearchReceivablesVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/project")
@Slf4j
public class ProjectController {

    @Resource
    private ProjectService projectService;

    @PostMapping("/searchProject")
    public ResponseResult<ResPage<List<ProjectVo>>> searchProject(@RequestBody SearchProjectVo searchProjectVo){
        log.info(searchProjectVo.toString());
        ResPage<List<ProjectVo>> resPage = projectService.searchProject(searchProjectVo);
        return new ResponseResult(ResponseResult.OK,resPage);
    }

    @PostMapping("/addProject")
    public ResponseResult<Boolean> addProject(@RequestBody AddProjectVo addProjectVo){
        log.debug(addProjectVo.toString());
        return new ResponseResult<>(ResponseResult.OK, projectService.addProject(addProjectVo));
    }

    @PutMapping("/updateProject")
    public ResponseResult<Boolean> updateProject(@RequestBody AddProjectVo addProjectVo){
        return new ResponseResult<>(ResponseResult.OK, projectService.updateProject(addProjectVo));
    }

    @GetMapping("/checkDetail/{pno}")
    public ResponseResult<AddProjectVo> checkDetail(@PathVariable("pno") String pno){
        return new ResponseResult<>(ResponseResult.OK, projectService.checkDetail(pno));
    }

    @PostMapping("/passPreliminaryExamination")
    public ResponseResult<Boolean> passPreliminaryExamination(@RequestBody ProjectVo projectVo){
        return new ResponseResult<>(ResponseResult.OK, projectService.passPreliminaryExamination(projectVo));
    }

    @PostMapping("/searchExamineProject")
    public ResponseResult<ResPage<List<ProjectVo>>> searchExamineProject(@RequestBody SearchProjectVo searchProjectVo){
        ResPage<List<ProjectVo>> resPage = projectService.searchExamineProject(searchProjectVo);
        return new ResponseResult(ResponseResult.OK,resPage);
    }

    @PutMapping("/withdrawProject")
    public ResponseResult<Boolean> withdrawProject(@RequestBody ProjectVo project){
        return new ResponseResult<>(ResponseResult.OK, projectService.withdrawProject(project));
    }
    /**
     * 获取首页数据
     */
    @GetMapping("/getIndexData")
    public ResponseResult<IndexData> getIndexData(){
        return new ResponseResult<>(ResponseResult.OK, projectService.getIndexData());
    }

    @GetMapping("/checkReceivables/{pno}")
    public ResponseResult<List<SearchReceivablesVo>> checkReceivables(@PathVariable("pno") String pno){
        return new ResponseResult<>(ResponseResult.OK, projectService.checkReceivables(pno));
    }

    @PostMapping("/searchFullProject")
    public ResponseResult<ResPage<List<ProjectVo>>> searchFullProject(@RequestBody SearchProjectVo searchProjectVo){
        ResPage<List<ProjectVo>> resPage = projectService.searchFullProject(searchProjectVo);
        return new ResponseResult(ResponseResult.OK,resPage);
    }

    @PostMapping("/ReviewFailed")
    public ResponseResult<Boolean> ReviewFailed(@RequestBody ProjectVo projectVo){
        return new ResponseResult<>(ResponseResult.OK, projectService.ReviewFailed(projectVo));
    }

    @PostMapping("/passReexamine")
    public ResponseResult<Boolean> passReexamine(@RequestBody ProjectVo projectVo){
        return new ResponseResult<>(ResponseResult.OK, projectService.passReexamine(projectVo));
    }

    @PostMapping("/searchReviewProject")
    public ResponseResult<ResPage<List<ReviewProjectVo>>> searchReviewProject(@RequestBody SearchProjectVo searchProjectVo){
        ResPage<List<ReviewProjectVo>> resPage = projectService.searchReviewProject(searchProjectVo);
        return new ResponseResult<>(ResponseResult.OK, resPage);
    }

    @PostMapping("/bid")
    public ResponseResult<Boolean> bid(@RequestBody Invest invest){
        return new ResponseResult<>(ResponseResult.OK,projectService.bid(invest));
    }

}
